package org.mdrtwell.reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class InvokeTester {
	public int add(int a, int b) {
		return a + b;
	}

	public String echo(String str) {
		return "echo:" + str;
	}

	public static void main(String[] args) {
		Class<?> clazz = InvokeTester.class;
		try {
			Object invokeTester = clazz.newInstance();
			// Object invokeTester = clazz.getConstructor().newInstance();
			Method addMethod = clazz.getMethod("add", new Class[] { int.class, int.class });
			Object result = addMethod.invoke(invokeTester, new Object[] { new Integer(100),
					new Integer(300) });
			System.out.println(result);
			Method echoMethod = clazz.getMethod("echo", new Class[] { String.class });
			result = echoMethod.invoke(invokeTester, new Object[] { "���" });
			System.out.println(result);
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
